package cn.shengchao.examstar.ai.application.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.shengchao.examstar.ai.application.service.AIWorkflowApplicationService;
import cn.shengchao.examstar.ai.domain.repository.IAiChatFreeSunRepository;
import cn.shengchao.examstar.ai.domain.service.KnowledgeDomainService;
import cn.shengchao.examstar.ai.domain.valueobject.SpecificationType;
import cn.shengchao.examstar.ai.domain.valueobject.UserId;
import cn.shengchao.examstar.ai.shared.enums.AiChatFreeType;
import cn.shengchao.examstar.rpc.distribute.enums.DistributeSaleRoleEnum;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@RequiredArgsConstructor
public class AIWorkflowApplicationServiceImpl implements AIWorkflowApplicationService {

    private final KnowledgeDomainService knowledgeDomainService;
    private final IAiChatFreeSunRepository iAiChatFreeSunRepository;


    @Override
    public String getHierarchicalSpecificationTypeName(SpecificationType specificationTypeId) {
        return knowledgeDomainService.getHierarchicalSpecificationTypeName(specificationTypeId);
    }

    @Override
    public String getKnowledgeLeafNodeNames(UserId userId, SpecificationType specificationTypeId) {
        return knowledgeDomainService.getKnowledgeLeafNodeNames(userId, specificationTypeId);
    }

    @Override
    public String getKnowledgeLeafNodesAsJson(UserId userId, SpecificationType specificationTypeId) {
        return knowledgeDomainService.getKnowledgeLeafNodesAsJson(userId, specificationTypeId);
    }

    @Override
    public Long getFreeSum(Long userId, AiChatFreeType aiChatFreeType) {
        Long freeSum = iAiChatFreeSunRepository.getAiChatFreeCount(aiChatFreeType);
        Long sum = iAiChatFreeSunRepository.getUserDoCount(userId, DateUtil.beginOfMonth(new Date()), new Date());
        return freeSum - sum;
    }
}